<template>
  <div>
    <van-nav-bar safe-area-inset-top placeholder :title="$t('Meter')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('MeterFunction')" name="1">
          <enablepublicVue :subOption="$t('MeterFunction')" :columns="toggleArr" :setValue="LocalArr.MeterFunctionValue"></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Meter1ID')" name="2">
          <tstartVue :setMin="1" :setMax="200" :subOption="'Meter1_ID'" :setValue.sync="Meter1IDValue"></tstartVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Meter2ID')" name="3">
          <tstartVue :setMin="1" :setMax="200" :subOption="'Meter2_ID'" :setValue.sync="Meter2IDValue"></tstartVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="4">
          <resetErrorLogsVue :setName="$t('ResetMeter1Energy')" :subOption="'ResetMeter1Energy'"></resetErrorLogsVue>
          <resetErrorLogsVue :setName="$t('ResetMeter2Energy')" :subOption="'ResetMeter2Energy'"></resetErrorLogsVue>
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import enablepublicVue from '../../../components/EnablePublic/EnablePublic'
import tstartVue from '../../../components/TStart/TStart'
import resetErrorLogsVue from '../../../components/ResetErrorLogs/ResetErrorLogs'

export default {
  components:{
    enablepublicVue,
    tstartVue,
    resetErrorLogsVue
  },
  data(){
    return {
      isLoading:false,
      activeNames:[],
      toggleArr:[this.$t('Disable'),this.$t('Enable')],
      Meter1IDValue:'',
      Meter2IDValue:'',
      LocalArr:{
        MeterFunctionValue:''
      }
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/setting'});
    },
    //获取设置数据
    async getData(){
      this.comm.loadingShow();
      let datas = await this.SETAPI.setGetData(localStorage.getItem('domain'),{'tokenId':localStorage.getItem('tokenId'),'sn':localStorage.getItem('wifiSN')});
      if(datas.result!=null&&datas.result!="tokenId不合法!"){
        let dataArr=JSON.parse(datas.result);
        this.LocalArr.MeterFunctionValue=dataArr[146];
        this.Meter1IDValue=dataArr[147];
        this.Meter2IDValue=dataArr[148];
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    onRefresh(){
      this.isLoading = false;
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
    }
  },
  mounted(){
    this.getData();
  }
}
</script>

<style scoped lang="less">

</style>
